package com.lc.afbx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lc.afbx.R;
import com.lc.afbx.beans.BusinessType;
import com.zcx.helper.bound.BoundView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/5/23.
 */
public class BusinessInsuranceChooseLevelActivity extends BaseActivity implements View.OnClickListener {


    private Bundle bundle;

    @BoundView(R.id.cheSunShi_cbox_rl) private RelativeLayout cheSunShi_cbox_rl;
    private CheckBox cheSunShi_btn1;
    private CheckBox cheSunShi_btn2;
    private TextView cheSunShi_txt;
    //    绝对免赔额
    private CheckBox cheSunMianPei_button2;
    private TextView cheSunMianPei_txt;
    //    第三者
    @BoundView(R.id.third_cbox_rl) private RelativeLayout third_cbox_rl;
    private CheckBox third_button1;
    private CheckBox third_button2;
    private TextView third_txt;
    //    全车抢道险
    @BoundView(R.id.qiangDaoXian_cbox_rl) private RelativeLayout qiangDaoXian_cbox_rl;
    private CheckBox qiangDaoXian_button1;
    private CheckBox qiangDaoXian_button2;
    private TextView qiangDaoXian_txt;
    //    司机责任险
    @BoundView(R.id.driver_cbox_rl) private RelativeLayout driver_cbox_rl;
    private CheckBox driver_button1;
    private CheckBox driver_button2;
    private TextView driver_txt;
    //乘客责任险
    @BoundView(R.id.passenger_cbox_rl) private RelativeLayout passenger_cbox_rl;
    private CheckBox passenger_btn1;
    private CheckBox passenger_btn2;
    private TextView passenger_txt;
    //不计免赔
    @BoundView(R.id.mianpei_cbox_rl) private RelativeLayout mianpei_cbox_rl;
    private CheckBox mianPei_button1;
    //玻璃单独破碎
    @BoundView(R.id.glass_cbox_rl) private RelativeLayout glass_cbox_rl;
    private CheckBox glass_button1;
    private TextView glass_txt;
    //自燃损失险
    @BoundView(R.id.naturalLoss_cbox_rl) private RelativeLayout naturalLoss_cbox_rl;
    private CheckBox naturalLoss_button1;
    private CheckBox naturalLoss_button2;
    private TextView naturalLoss_txt;
    //车划痕
    @BoundView(R.id.cheHuaHen_cbox_rl) private RelativeLayout cheHuaHen_cbox_rl;
    private CheckBox cheHuaHen_button1;
    private TextView cheHuaHen_txt;
    //发动机涉水
    @BoundView(R.id.engine_cbox_rl) private RelativeLayout engine_cbox_rl;
    private CheckBox engine_button1;
    private CheckBox engine_button2;
    //指定修理厂
    @BoundView(R.id.repairFactory_cbox_rl) private RelativeLayout repairFactory_cbox_rl;
    private CheckBox repairFactory_button1;
    //新增设备
    @BoundView(R.id.damage_cbox_rl) private RelativeLayout damage_cbox_rl;
    private CheckBox damage_button1;
    private CheckBox damage_button2;
    private TextView damage_txt;
    //第三方特约险
    @BoundView(R.id.SpecialRisks_cbox_rl) private RelativeLayout SpecialRisks_cbox_rl;
    private CheckBox specialRisks_btton1;

    private List<BusinessType> typeList = new ArrayList<>();
    private Map<Integer, BusinessType> typeMap = new HashMap<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shouye_shangyexian_xuanzexianbie);

        initView();

        setListener();

        bundle = getIntent().getExtras();

        for (int i = 0; i < 14; i++) {

            typeList.add(new BusinessType());

            BusinessType business = new BusinessType();

            if (i == 0) {

                business.setType("车辆损失险");
                business.setIsFree(false);
                business.setMoney("0");
            } else if (i == 1) {

                business.setType("车损绝对免赔额");
                business.setMoney("600");
                business.setIsFree(false);
            }  else if (i == 2) {

                business.setType("第三者责任险");
                business.setMoney("0");
                business.setIsFree(false);
            }  else if (i == 3) {

                business.setType("全车抢盗险");
                business.setMoney("0");
                business.setIsFree(false);
            }  else if (i == 4) {

                business.setType("司机责任险");
                business.setMoney("0");
                business.setIsFree(false);
            }  else if (i == 5) {

                business.setType("乘客责任险");
                business.setMoney("0");
                business.setIsFree(false);
            }  else if (i == 6) {

                business.setType("不计免赔率");
                business.setMoney("0");
                business.setIsFree(false);
            }  else if (i == 7) {

                business.setType("玻璃单独破碎险");
                business.setMoney("0");
                business.setIsFree(false);
            }  else if (i == 8) {

                business.setType("自燃损失险");
                business.setMoney("0");
                business.setIsFree(false);
            }  else if (i == 9) {

                business.setType("车划痕损失险");
                business.setMoney("0");
                business.setIsFree(false);
            }  else if (i == 10) {

                business.setType("发动机涉水损失险");
                business.setMoney("0");
                business.setIsFree(false);
            }  else if (i == 11) {

                business.setType("指定修理厂险");
                business.setMoney("0");
                business.setIsFree(false);
            }  else if (i == 12) {

                business.setType("新增设备损失险");
                business.setMoney("0");
                business.setIsFree(false);
            }  else if (i == 13) {

                business.setType("车辆损失保险无法找到第三方特约险");
                business.setMoney("0");
                business.setIsFree(false);
            }

            typeMap.put(i, business);

        }

    }

    private void setListener() {
        cheSunShi_btn1.setOnClickListener(this);
        cheSunShi_btn2.setOnClickListener(this);
        cheSunShi_cbox_rl.setOnClickListener(this);
        third_cbox_rl.setOnClickListener(this);
        qiangDaoXian_cbox_rl.setOnClickListener(this);
        driver_cbox_rl.setOnClickListener(this);
        passenger_cbox_rl.setOnClickListener(this);
        mianpei_cbox_rl.setOnClickListener(this);
        glass_cbox_rl.setOnClickListener(this);
        naturalLoss_cbox_rl.setOnClickListener(this);
        cheHuaHen_cbox_rl.setOnClickListener(this);
        engine_cbox_rl.setOnClickListener(this);
        repairFactory_cbox_rl.setOnClickListener(this);
        damage_cbox_rl.setOnClickListener(this);
        SpecialRisks_cbox_rl.setOnClickListener(this);

    }

    private void initView() {

        findViewById(R.id.back).setOnClickListener(this);
        findViewById(R.id.shouye_btn_shangyexian_xuezexianbie_xiayibu).setOnClickListener(this);

        //车辆损失
        cheSunShi_btn1 = ((CheckBox) findViewById(R.id.cheSunShi_btn1));
        cheSunShi_btn2 = ((CheckBox) findViewById(R.id.cheSunShi_btn2));
        cheSunShi_txt = ((TextView) findViewById(R.id.cheSunShi_txt));
        //车损绝对免赔额
        cheSunMianPei_button2 = ((CheckBox) findViewById(R.id.cheSunMianPei_button2));
        cheSunMianPei_txt = ((TextView) findViewById(R.id.cheSunMianPei_txt));
        //第三者责任险
        third_button1 = ((CheckBox) findViewById(R.id.Third_button1));
        third_button2 = ((CheckBox) findViewById(R.id.Third_button2));
        third_txt = ((TextView) findViewById(R.id.Third_txt));
        //全车抢道险
        qiangDaoXian_button1 = ((CheckBox) findViewById(R.id.QiangDaoXian_button1));
        qiangDaoXian_button2 = ((CheckBox) findViewById(R.id.QiangDaoXian_button2));
        qiangDaoXian_txt = ((TextView) findViewById(R.id.QiangDaoXian_txt));
        // 司机责任险
        driver_button1 = ((CheckBox) findViewById(R.id.driver_button1));
        driver_button2 = ((CheckBox) findViewById(R.id.driver_button2));
        driver_txt = ((TextView) findViewById(R.id.driver_txt));
        //乘客责任险
        passenger_btn1 = ((CheckBox) findViewById(R.id.passenger_btn1));
        passenger_btn2 = ((CheckBox) findViewById(R.id.passenger_btn2));
        passenger_txt = ((TextView) findViewById(R.id.passenger_txt));
        //不计免赔率
        mianPei_button1 = (CheckBox) findViewById(R.id.MianPei_button1);
        // 玻璃破碎险
        glass_button1 = (CheckBox) findViewById(R.id.glass_button1);
        glass_txt = (TextView) findViewById(R.id.glass_txt);
        //自燃损失险
        naturalLoss_button1 = ((CheckBox) findViewById(R.id.naturalLoss_button1));
        naturalLoss_button2 = ((CheckBox) findViewById(R.id.naturalLoss_button2));
        naturalLoss_txt = ((TextView) findViewById(R.id.naturalLoss_txt));
        //车身划痕损失险
        cheHuaHen_button1 = ((CheckBox) findViewById(R.id.cheHuaHen_button1));
        cheHuaHen_txt = ((TextView) findViewById(R.id.cheHuaHen_txt));
        //发动机涉水损失险
        engine_button1 = ((CheckBox) findViewById(R.id.engine_button1));
        engine_button2 = ((CheckBox) findViewById(R.id.engine_button2));
        //指定修理厂险
        repairFactory_button1 = (CheckBox) findViewById(R.id.repairFactory_button1);
        //新增设备损失险
        damage_button1 = ((CheckBox) findViewById(R.id.damage_button1));
        damage_button2 = ((CheckBox) findViewById(R.id.damage_button2));
        damage_txt = ((TextView) findViewById(R.id.damage_txt));
        //车辆损失保险无法找到第三方特约险
        specialRisks_btton1 = ((CheckBox) findViewById(R.id.SpecialRisks_btton1));

    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            //车辆损失
            case R.id.cheSunShi_cbox_rl:
//                UtilLog.e("cheSunShi_btn1========", cheSunShi_btn1.isChecked() + "");

                if (!cheSunShi_btn1.isChecked()) {

                    cheSunShi_btn1.setChecked(true);
                    cheSunShi_btn2.setChecked(true);

                    cheSunShi_btn2.setEnabled(true);
                    cheSunShi_txt.setText("600");

                    BusinessType business = typeMap.get(0);
                    business.setMoney("600");

                    typeMap.put(0, business);

                } else {

                    cheSunShi_btn1.setChecked(false);

                    cheSunShi_btn2.setEnabled(false);
                    cheSunShi_btn2.setChecked(false);

                    cheSunShi_txt.setText("");

                    BusinessType business = typeMap.get(0);
                    business.setMoney("0");

                    typeMap.put(0, business);

                }

                return;

            case R.id.cheSunShi_btn2:

                if (cheSunShi_btn2.isChecked()) {

                    cheSunShi_txt.setText("600");

                    BusinessType business = typeMap.get(0);

                    business.setIsFree(true);

                    typeMap.put(0, business);
                    business.setMoney("600");


                } else {

                    cheSunShi_txt.setText("400");

                    BusinessType business = typeMap.get(0);

                    business.setIsFree(false);
                    business.setMoney("400");

                    typeMap.put(0, business);

                }
                return;

            //车损绝对免赔额
            case R.id.cheSunMianPei_button2:

                if (cheSunMianPei_button2.isChecked()) {

                    cheSunMianPei_txt.setText("600");

                    BusinessType business = typeMap.get(1);

                    business.setIsFree(true);
                    business.setMoney("600");

                    typeMap.put(1, business);


                } else {

                    cheSunMianPei_txt.setText("400");

                    BusinessType business = typeMap.get(1);

                    business.setIsFree(true);
                    business.setMoney("400");

                    typeMap.put(1, business);

                }

                return;

            //第三者责任险
            case R.id.third_cbox_rl:

                if (!third_button1.isChecked()) {

                    third_button1.setChecked(true);
                    third_button2.setChecked(true);

                    third_button2.setEnabled(true);

                    third_txt.setText("600");

                    BusinessType business = typeMap.get(2);
                    business.setMoney("600");

                    typeMap.put(2, business);

                } else {

                    third_button1.setChecked(false);

                    third_button2.setEnabled(false);
                    third_button2.setChecked(false);

                    third_txt.setText("");

                    BusinessType business = typeMap.get(2);
                    business.setMoney("0");

                    typeMap.put(2, business);

                }

                return;

            case R.id.Third_button2:

                if (third_button2.isChecked()) {

                    third_txt.setText("600");

                    BusinessType business = typeMap.get(2);
                    business.setIsFree(true);
                    business.setMoney("600");

                    typeMap.put(2, business);


                } else {

                    third_txt.setText("400");

                    BusinessType business = typeMap.get(2);
                    business.setIsFree(false);
                    business.setMoney("400");

                    typeMap.put(2, business);

                }

                return;

            //全车抢道险
            case R.id.qiangDaoXian_cbox_rl:

                if (!qiangDaoXian_button1.isChecked()) {

                    qiangDaoXian_button1.setChecked(true);

                    qiangDaoXian_button2.setChecked(true);
                    qiangDaoXian_button2.setEnabled(true);

                    qiangDaoXian_txt.setText("600");

                    BusinessType business = typeMap.get(3);
                    business.setMoney("600");

                    typeMap.put(3, business);

                } else {

                    qiangDaoXian_button1.setChecked(false);

                    qiangDaoXian_button2.setEnabled(false);
                    qiangDaoXian_button2.setChecked(false);

                    qiangDaoXian_txt.setText("");

                    BusinessType business = typeMap.get(3);
                    business.setMoney("0");

                    typeMap.put(3, business);

                }

                return;

            case R.id.QiangDaoXian_button2:

                if (qiangDaoXian_button2.isChecked()) {

                    qiangDaoXian_txt.setText("600");

                    BusinessType business = typeMap.get(3);

                    business.setMoney("600");
                    business.setIsFree(true);

                    typeMap.put(3, business);

                } else {

                    qiangDaoXian_txt.setText("400");

                    BusinessType business = typeMap.get(3);

                    business.setMoney("400");
                    business.setIsFree(false);

                    typeMap.put(3, business);

                }

                return;

            // 司机责任险
            case R.id.driver_cbox_rl:

                if (!driver_button1.isChecked()) {

                    driver_button1.setChecked(true);
                    driver_button2.setChecked(true);

                    driver_button2.setEnabled(true);

                    driver_txt.setText("600");

                    BusinessType business = typeMap.get(4);

                    business.setMoney("600");

                    typeMap.put(4, business);


                } else {

                    driver_button1.setChecked(false);

                    driver_button2.setEnabled(false);
                    driver_button2.setChecked(false);

                    driver_txt.setText("");

                    BusinessType business = typeMap.get(4);

                    business.setMoney("0");

                    typeMap.put(4, business);

                }

                return;

            case R.id.driver_button2:

                if (driver_button2.isChecked()) {

                    driver_txt.setText("600");

                    BusinessType business = typeMap.get(4);

                    business.setMoney("600");
                    business.setIsFree(true);

                    typeMap.put(4, business);


                } else {

                    driver_txt.setText("400");

                    BusinessType business = typeMap.get(4);

                    business.setMoney("400");
                    business.setIsFree(false);

                    typeMap.put(4, business);


                }

                return;

            //乘客责任险
            case R.id.passenger_cbox_rl:

                if (!passenger_btn1.isChecked()) {

                    passenger_btn1.setChecked(true);

                    passenger_btn2.setChecked(true);
                    passenger_btn2.setEnabled(true);

                    passenger_txt.setText("600");

                    BusinessType business = typeMap.get(5);

                    business.setMoney("600");

                    typeMap.put(5, business);

                } else {

                    passenger_btn1.setChecked(false);

                    passenger_btn2.setEnabled(false);
                    passenger_btn2.setChecked(false);

                    passenger_txt.setText("");

                    BusinessType business = typeMap.get(5);

                    business.setMoney("0");

                    typeMap.put(5, business);

                }

                return;

            case R.id.passenger_btn2:

                if (passenger_btn2.isChecked()) {

                    passenger_txt.setText("600");

                    BusinessType business = typeMap.get(5);

                    business.setMoney("600");
                    business.setIsFree(true);

                    typeMap.put(5, business);


                } else {

                    passenger_txt.setText("400");

                    BusinessType business = typeMap.get(5);

                    business.setMoney("400");
                    business.setIsFree(false);

                    typeMap.put(5, business);

                }

                return;

            //不计免赔率
            case R.id.mianpei_cbox_rl:

                if (!mianPei_button1.isChecked()) {

                    mianPei_button1.setChecked(true);
                    BusinessType business = typeMap.get(6);

                    business.setMoney("600");

                    typeMap.put(6, business);

                } else {

                    mianPei_button1.setChecked(false);

                    BusinessType business = typeMap.get(6);

                    business.setMoney("0");

                    typeMap.put(6, business);

                }

                return;

            //玻璃破碎险
            case R.id.glass_cbox_rl:

                if (!glass_button1.isChecked()) {

                    glass_button1.setChecked(true);

                    glass_txt.setText("600");

                    BusinessType business = typeMap.get(7);

                    business.setMoney("600");

                    typeMap.put(7, business);

                } else {

                    glass_button1.setChecked(false);

                    glass_txt.setText("");

                    BusinessType business = typeMap.get(7);

                    business.setMoney("0");

                    typeMap.put(7, business);

                }

                break;

            //自燃损失险
            case R.id.naturalLoss_cbox_rl:

                if (!naturalLoss_button1.isChecked()) {

                    naturalLoss_button1.setChecked(true);

                    naturalLoss_button2.setChecked(true);
                    naturalLoss_button2.setEnabled(true);

                    naturalLoss_txt.setText("600");

                    BusinessType business = typeMap.get(8);

                    business.setMoney("600");

                    typeMap.put(8, business);

                } else {

                    naturalLoss_button1.setChecked(false);

                    naturalLoss_button2.setEnabled(false);
                    naturalLoss_button2.setChecked(false);

                    naturalLoss_txt.setText("");

                    BusinessType business = typeMap.get(8);

                    business.setMoney("0");

                    typeMap.put(8, business);

                }

                return;

            case R.id.naturalLoss_button2:

                if (naturalLoss_button2.isChecked()) {

                    naturalLoss_txt.setText("600");

                    BusinessType business = typeMap.get(8);

                    business.setMoney("600");
                    business.setIsFree(true);

                    typeMap.put(8, business);

                } else {

                    naturalLoss_txt.setText("400");

                    BusinessType business = typeMap.get(8);

                    business.setMoney("400");
                    business.setIsFree(false);

                    typeMap.put(8, business);

                }

                return;

            //车身划痕损失险
            case R.id.cheHuaHen_cbox_rl:

                if (!cheHuaHen_button1.isChecked()) {

                    cheHuaHen_button1.setChecked(true);
                    cheHuaHen_txt.setText("600");

                    BusinessType business = typeMap.get(9);

                    business.setMoney("600");

                    typeMap.put(9, business);

                } else {

                    cheHuaHen_button1.setChecked(false);

                    cheHuaHen_txt.setText("");

                    BusinessType business = typeMap.get(9);

                    business.setMoney("0");

                    typeMap.put(9, business);
                }

                return;

            //发动机涉水损失险
            case R.id.engine_cbox_rl:

                if (!engine_button1.isChecked()) {

                    engine_button1.setChecked(true);
                    engine_button2.setChecked(true);
                    engine_button2.setEnabled(true);

                    BusinessType business = typeMap.get(10);

                    business.setMoney("600");

                    typeMap.put(10, business);

                } else {

                    engine_button1.setChecked(false);

                    engine_button2.setEnabled(false);

                    engine_button2.setChecked(false);

                    BusinessType business = typeMap.get(10);

                    business.setMoney("0");

                    typeMap.put(10, business);

                }

                return;

            case R.id.engine_button2:

                if (engine_button2.isChecked()) {


                    BusinessType business = typeMap.get(10);

                    business.setMoney("600");
                    business.setIsFree(true);

                    typeMap.put(10, business);

                } else {

                    BusinessType business = typeMap.get(10);

                    business.setMoney("400");
                    business.setIsFree(false);

                    typeMap.put(10, business);

                }

                return;

            //指定修理厂险
            case R.id.repairFactory_cbox_rl:

                if (!repairFactory_button1.isChecked()) {

                    repairFactory_button1.setChecked(true);

                    BusinessType business = typeMap.get(11);

                    business.setMoney("600");

                    typeMap.put(11, business);

                } else {

                    repairFactory_button1.setChecked(false);

                    BusinessType business = typeMap.get(11);

                    business.setMoney("0");

                    typeMap.put(11, business);

                }

                return;

            //新增设备损失险
            case R.id.damage_cbox_rl:

                if (!damage_button1.isChecked()) {

                    damage_button1.setChecked(true);
                    damage_button2.setChecked(true);
                    damage_button2.setEnabled(true);

                    damage_txt.setText("600");

                    BusinessType business = typeMap.get(12);

                    business.setMoney("600");

                    typeMap.put(12, business);

                } else {

                    damage_button1.setChecked(false);

                    damage_button2.setEnabled(false);
                    damage_button2.setChecked(false);
                    damage_txt.setText("");

                    BusinessType business = typeMap.get(12);

                    business.setMoney("0");

                    typeMap.put(12, business);

                }

                return;

            case R.id.damage_button2:

                if (damage_button2.isChecked()) {

                    damage_txt.setText("600");

                    BusinessType business = typeMap.get(12);

                    business.setMoney("600");
                    business.setIsFree(true);

                    typeMap.put(12, business);

                } else {

                    damage_txt.setText("400");

                    BusinessType business = typeMap.get(12);

                    business.setMoney("400");
                    business.setIsFree(false);

                    typeMap.put(12, business);

                }

                return;

            //车辆损失保险无法找到第三方特约险
            case R.id.SpecialRisks_cbox_rl:

                if (!specialRisks_btton1.isChecked()) {

                    specialRisks_btton1.setChecked(true);

                    BusinessType business = typeMap.get(13);

                    business.setMoney("600");

                    typeMap.put(13, business);

                } else {

                    specialRisks_btton1.setChecked(false);

                    BusinessType business = typeMap.get(13);

                    business.setMoney("0");

                    typeMap.put(13, business);

                }

                return;

            case R.id.shouye_btn_shangyexian_xuezexianbie_xiayibu:

                bundle.putSerializable("businessType", (Serializable) typeMap);

                if (bundle.getString("insurance_type").equals("1")) {

                    // 新保
                    startActivity(new Intent(this, BusinessInsurancePriceActivity.class).putExtras(bundle));

                } else {

                    // 续保
                    startActivity(new Intent(this, BusinessXubaoPriceActivity.class).putExtras(bundle));

                }

                break;
        }
    }


}
